<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const initialState = {
      count: 0,
      name: 'tom'
    }
    // function reducer(state = initialState, action) {
    //   switch (action.type) {
    //     case 'ADD':
    //       return { ...state, count: state.count + action.payload }
    //       break;
    //   }
    // }

    // const store = Redux.createStore(reducer)

    // store.subscribe(() => {
    //   console.log(store.getState())
    // })

    // store.dispath({ type: 'ADD', payload: 3 })


    // const createStore = (function () {
    //   let instance = null

    //   class Store {
    //     constructor(reducer, initialState) {
    //       this.reducer = reducer
    //       this.callbacks = [];
    //       this.state = this.reducer(initialState, {})
    //     }
    //     getState() {
    //       return this.state
    //     }
    //     dispatch(action) {
    //       const newState = this.reducer(this.state, action)
    //       if (newState === this.state) {
    //         this.state = newState;
    //         return
    //       }
    //       this.callbacks.forEach(item => {
    //         item()
    //       })
    //     }
    //     subscribe(callback) {
    //       this.callbacks.push(callback)
    //     }
    //   }



    //   return (reducer, initialState) => {
    //     if (!instance) {
    //       instance = new Store(reducer, initialState)
    //     }
    //     return instance
    //   }
    // })()

    // function reducer(state = initialState, action) {
    //   const { payload, type } = action;

    //   switch (type) {
    //     case 'ADD':
    //       state.count++
    //       break;
    //   }
    //   return JSON.parse(JSON.stringify(state))
    // }
    // const store = createStore(reducer)
    // const store1 = createStore(reducer)
    // console.log(store.getState(), '初始值')
    // store.subscribe(() => {
    //   console.log('改变了', store.getState())
    // })
    // store1.subscribe(() => {
    //   console.log('改变了', store1.getState())
    // })
    // store.dispatch({
    //   type: 'ADD',
    //   payload: {}
    // })



    // console.log(store.getState(), '改变后')

    // Toast.show('title1')
   // Toast.show('title2')
   // Toast.show('title3')
// title1 2s -> 消失 -> title2 -> 消失 -> title3 -> 消失
  </script>
</body>

</html>